import { createRouter, createWebHistory } from 'vue-router'

import AppLayout from '@/components/layout/AppLayout.vue'
import AppLayout1 from '@/views/restaurantLayout/AppLayout.vue'
import IndexView from '@/views/IndexView.vue'
// import { useTokenStore } from '@/stores/mytoken'
import usersManagement from '@/views/users/usersIndex.vue'
import userinfo from '@/views/users/components/userInfo.vue'

// const store = useTokenStore()

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '',
      name: 'login',
      component: () => import('@/views/login/LoginView.vue')
    },
    {
      path: '/test01',
      name: 'test01',
      component: () => import('@/views/login/test01.vue')
    },
    {
      path: '/test02',
      name: 'test02',
      component: () => import('@/views/login/test02.vue')
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/views/login/register.vue')
    },
    {
      path: '/layout',
      name: 'layout',
      component: AppLayout,
      // 是否需要跳转的这一页面的验证，/根目录需要验证，下面的子路由都需要验证
      // meta:{requiresAuth:true},
      children: [
        {
          path: '/home',
          name: 'home',
          component: IndexView
        },
        {
          path: '/about',
          name: 'about',
          // 懒加载
          component: () => import('@/views/about.vue')
        },
        {
          path: 'menus',
          name: 'menus',
          component: () => import('@/views/menu/MenuIndex.vue')
        },
        {
          path: 'inspectQualification',
          name: 'inspectQualification',
          component: () => import('@/views/users/inspectQualification.vue')
        },
        {
          path: 'inspectComplain',
          name: 'inspectComplain',
          component: () => import('@/views/manager/inspectComplain.vue')
        },
        {
          path: 'restaurantManagement',
          name: 'restaurantManagement',
          component: () => import('@/views/manager/restaurantManagement.vue')
        },
        {
          path: 'usersManagement',
          name: 'usersManagement',
          component: usersManagement
        },
        {
          //NotFound错误页面
          path: '/:xxx(.*)*',
          name: 'ErrorPage',
          component: () => import('@/views/ErrorPage.vue')
        }
      ]
    },
    // 商家开始
    {
      path: '/AppLayout1',
      name: 'AppLayout1',
      component: AppLayout1,
      children: [
        {
          path: 'indexView',
          component: IndexView
        },
        {
          path: 'shopmanagement',
          name: 'shopmanagement',
          component: () => import('@/views/restaurantLayout/shopmanagement.vue')
        },
        {
          path: 'shopmanagement1',
          name: 'shopmanagement1',
          component: () => import('@/views/restaurantLayout/shopmanagement1.vue')
        },
        {
          path: 'shopinformation',
          name: 'shopinformation',
          component: () => import('@/views/restaurantLayout/shopinformation.vue')
        },
        {
          path: 'ComplaintComment',
          name: 'ComplaintComment',
          component: () => import('@/views/restaurantLayout/ComplaintComment.vue')
        },
        {
          path: 'finishedOrder',
          name: 'finishedOrder',
          component: () => import('@/views/restaurantLayout/finishedOrder.vue')
        },
        {
          path: 'refundedOrder',
          name: 'refundedOrder',
          component: () => import('@/views/restaurantLayout/refundedOrder.vue')
        }
      ]
    },
    {
      path: '/shangjiascreen',
      name: 'shangjiascreen',
      component: () => import('@/views/screen/shangjia_screen.vue')
    },
    {
      path: '/screen',
      name: 'screen',
      component: () => import('@/views/screen/index.vue')
    },
    {
      path: '/text',
      name: 'text',
      component: () => import('@/views/screen/text.vue')
    },
    {
      path: '/all',
      name: 'all',
      component: () => import('@/views/screen/all.vue')
    },
    {
      path: '/clientdraw',
      name: 'clientdraw',
      component: () => import('@/views/screen/userdraw.vue')
    },

    // 商家结束
    {
      path: '/index',
      name: 'index',
      component: () => import('@/views/order/index.vue')
    },
    {
      path: '/shangjia',
      name: 'shangjia',
      component: () => import('@/views/order/shangjia.vue')
    },
    {
      path: '/detail',
      name: 'detail',
      component: () => import('@/views/order/shangjia_detail.vue')
    },
    {
      path: '/pay',
      name: 'pay',
      component: () => import('@/views/order/pay.vue')
    },
    {
      path: '/shopMap',
      name: 'shopMap',
      component: () => import('@/views/order/shopMap.vue')
    },
    {
      path: '/chat',
      name: 'Chat',
      component: () => import('@/views/order/Chat.vue')
    },
    {
      path: '/perCenter',
      name: 'perCenter',
      component: () => import('@/views/users/components/layout/LayoutPerCenter.vue'),
      children: [
        {
          path: 'userInfo',
          name: 'userInfo',
          component: userinfo
        },
        {
          path: 'order',
          name: 'order',
          component: () => import('@/views/users/components/userOrder.vue')
        },
        {
          path: 'userComment',
          name: 'userComment',
          component: () => import('@/views/users/components/userComment.vue')
        },
        {
          path: 'userComplain',
          name: 'userComplain',
          component: () => import('@/views/users/components/userComplain.vue')
        },
        {
          path: '/yonghuscreen',
          name: 'yonghuscreen',
          component: () => import('@/views/screen/yonghu_screen.vue')
        }
      ]
    }
  ]
})
/* 
  路由守卫：在每一次路由地址变化之前:
  to:跳转到哪
  from:从哪里来
  next:将要干什么
*/

/* router.beforeEach((to,from,next)=>{
  //判断目标地址是否需要登录状态的判断
  if (to.matched.some((r)=>r.meta?.requiresAuth)){
     const store = useTokenStore()
     if (!store.token?.access_token){
      next({name:'login',query:{redirect:to.fullPath}})
      return 
     }

  }
  //拦住后看后续代码执不执行，取决于next,调用next往后走,不调用不往后走
  next()
}) */

export default router
